/*
 * ReplaceScreen.java
 * Created on August 12, 2008, 3:14 AM by Uru
 *
 * Allows a lua script to replace the top screen on the stack with another screen by name
 */

package ScreenSystem;

import org.keplerproject.luajava.*;

public class ReplaceScreen extends JavaFunction{
    LuaState L;
    
    public ReplaceScreen(LuaState l){
        super(l);
        L = l;
    }
    
    public int execute(){
        //get the screen's name
        int n = L.getTop();
        String name = L.toString(n);
        
        //push the screen
        Screen s = ScreenStack.getScreen(name);
        if(s != null){
            ScreenStack.replace(s);
        }else{
            System.err.println("Screen "+name+" is not registered.");
        }
        return 0;
    }
    
}